<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>购买页面</title>
    <script type="text/javascript" src="js/jquery-1.11.3.js"></script>
    <link href="css/buyBean.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div class="maindiv">
      <div class="buyBeanDiv">
        <div class="buyBeanDiv_radio">
          <div class="buyBeanDiv_radio_first">
            <label
              class="buyBeanDiv_radio_label"
              onclick="chooseNumber(this)"
              for="buyBeanNumber_6"
              ><i></i><span class="buyBeanDiv_radio_span_bean">600</span>
              <span class="buyBeanDiv_radio_span_money"
                >&yen;&nbsp;6</span
              ></label
            >
            <label
              class="buyBeanDiv_radio_label"
              onclick="chooseNumber(this)"
              for="buyBeanNumber_30"
              ><i></i><span class="buyBeanDiv_radio_span_bean">3000</span>
              <span class="buyBeanDiv_radio_span_money"
                >&yen;&nbsp;30</span
              ></label
            >
            <label
              class="buyBeanDiv_radio_label"
              onclick="chooseNumber(this)"
              for="buyBeanNumber_98"
              ><i></i><span class="buyBeanDiv_radio_span_bean">9800</span>
              <span class="buyBeanDiv_radio_span_money"
                >&yen;&nbsp;98</span
              ></label
            >
          </div>
          <div class="buyBeanDiv_radio_second">
            <label
              class="buyBeanDiv_radio_label"
              onclick="chooseNumber(this)"
              for="buyBeanNumber_198"
              ><i></i><span class="buyBeanDiv_radio_span_bean">19800</span>
              <span class="buyBeanDiv_radio_span_money"
                >&yen;&nbsp;198</span
              ></label
            >
            <label
              class="buyBeanDiv_radio_label"
              onclick="chooseNumber(this)"
              for="buyBeanNumber_328"
              ><i></i><span class="buyBeanDiv_radio_span_bean">32800</span>
              <span class="buyBeanDiv_radio_span_money"
                >&yen;&nbsp;328</span
              ></label
            >
            <label
              class="buyBeanDiv_radio_label"
              onclick="chooseNumber(this)"
              for="buyBeanNumber_648"
              ><i></i><span class="buyBeanDiv_radio_span_bean">64800</span>
              <span class="buyBeanDiv_radio_span_money"
                >&yen;&nbsp;648</span
              ></label
            >
          </div>
          <div class="buyBeanDiv_radio_third">
            <label
              id="buyBeanNumber_customize_radio"
              class="buyBeanDiv_radio_label"
              onclick="chooseNumber(this)"
              for="buyBeanNumber_customize"
            >
              <i></i><span class="buyBeanDiv_radio_span_bean">自定义</span>
              <input
                type="text"
                id="buyBeanNumber_customize_text"
                placeholder="自定义金额"
              />
            </label>
          </div>
        </div>
        <div class="buyBeanDiv_butten cleanBox">
          <a onclick="createOrder()">去支付</a>
        </div>
        <input
          id="buyBeanNumber_6"
          type="radio"
          name="buyBeanNumber"
          value="6"
          style="display: none"
        />
        <input
          id="buyBeanNumber_30"
          type="radio"
          name="buyBeanNumber"
          value="30"
          style="display: none"
        />
        <input
          id="buyBeanNumber_98"
          type="radio"
          name="buyBeanNumber"
          value="98"
          style="display: none"
        />
        <input
          id="buyBeanNumber_198"
          type="radio"
          name="buyBeanNumber"
          value="198"
          style="display: none"
        />
        <input
          id="buyBeanNumber_328"
          type="radio"
          name="buyBeanNumber"
          value="328"
          style="display: none"
        />
        <input
          id="buyBeanNumber_648"
          type="radio"
          name="buyBeanNumber"
          value="648"
          style="display: none"
        />
        <input
          id="buyBeanNumber_customize"
          type="radio"
          name="buyBeanNumber"
          value="customize"
          style="display: none"
        />
      </div>
    </div>
  </body>
  <script>
    $(function () {
      $(window.parent)[0].setiframeHight($("body").height());
    });

    function createOrder(Money) {
      var beanMoneyNumber;
      var beanMoney = $("input[name='buyBeanNumber']:checked").val();
      if (!beanMoney) {
        alert("请选择金额");
        return;
      }
      if (beanMoney == "customize") {
        var regex = /^[0-9]*$/;
        beanMoneyNumber = $("#buyBeanNumber_customize_text").val();
        if (beanMoneyNumber == "") {
          alert("请输入金额");
          return;
        }
        if (beanMoneyNumber.match(regex) == null) {
          alert("请输入整数");
          return;
        } else {
          var regex = /^\d{1,8}$/;
          if (beanMoneyNumber.match(regex) == null) {
            alert("请1亿以内的金额");
            return;
          }
          beanMoneyNumber = beanMoneyNumber.match(regex)[0];
        }
      } else {
        beanMoneyNumber = beanMoney;
      }
      console.log(beanMoneyNumber);
      $(window.parent)[0].openSharePay(beanMoneyNumber);
    }

    $("#buyBeanNumber_customize_text").focus(function () {
      $("#buyBeanNumber_customize_radio").click();
    });
    function chooseNumber(btn) {
      $(".buyBeanDiv_radio").find("label").removeClass("ischoose");
      $(btn).addClass("ischoose");
    }
  </script>
</html>
